package com.fanbai.score.user.activity;

import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.fanbai.score.R;
import com.fanbai.score.common.Manager.ActivityManager;
import com.fanbai.score.common.Utils.ImageUtils;
import com.fanbai.score.common.base.BaseActivity;
import com.fanbai.score.common.base.MyApplication;
import com.fanbai.score.common.http.CallBack;
import com.fanbai.score.user.bean.CartGoodsInfo_Bean;
import com.fanbai.score.user.bean.ProductInfo_Bean;
import com.fanbai.score.user.http.UserProduct_RequestNet_Utils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by acer on 2017/5/13.
 */

public class ShopDetails_Activity extends BaseActivity {

    @BindView(R.id.userActivityShopDetails_shopImg)
    ImageView iconImg;
    @BindView(R.id.userActivityShopDetails_shopName)
    TextView shopName;
    @BindView(R.id.userActivityShopDetails_shopDesc)
    TextView shopDesc;

    @BindView(R.id.userActivityShopDetails_value)
    TextView valueTxt;
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */

    @OnClick({R.id.userActivityShopDetails_MinusSign, R.id.userActivityShopDetails_Plus})
    public void onClick(View view) {
        int goodsCnt = Integer.valueOf(valueTxt.getText().toString());
        switch (view.getId()) {
            case R.id.userActivityShopDetails_MinusSign:
                if (goodsCnt > 1) {
                    goodsCnt--;
                }
                break;
            case R.id.userActivityShopDetails_Plus:
                goodsCnt++;
                break;
        }
        valueTxt.setText("" + goodsCnt);
    }

    @OnClick(R.id.userActivityShopDetails_nextBut)
    public void onClickBut() {
        CartGoodsInfo_Bean bean = new CartGoodsInfo_Bean();
        bean.setGoodsPid(productInfoBean.getPid());
        if(productInfoBean.getPimages() != null && productInfoBean.getPimages().size() > 0){
            bean.setGoodsImg(productInfoBean.getPimages().get(0));
        }else{
            bean.setGoodsImg("");
        }
        bean.setGoodsName(productInfoBean.getPname());
        bean.setGoodsPrice(Integer.valueOf(productInfoBean.getPprice()));
        bean.setGoodsCnt(Integer.valueOf(valueTxt.getText().toString()));
        MyApplication.getInstanti().addGoodsToUserCart(bean);
        jumpToActivity(ShopCart_Activity.class);
    }

    @Override
    protected int getLayoutID() {
        return R.layout.user_activity_shopdetails;
    }

    @Override
    public String getTitleName() {
        return "商品详情";
    }

    @Override
    protected void initView() {

    }
    ProductInfo_Bean productInfoBean;
    @Override
    protected void initData() {
        productInfoBean = getIntent().getExtras().getParcelable("bean");
        setData(productInfoBean);
    }

    @Override
    protected void initListener() {

    }

    private void setData(ProductInfo_Bean productInfoBean) {
        if (productInfoBean.getPimages() != null && productInfoBean.getPimages().size() > 0) {
            ImageUtils.show(ctx, productInfoBean.getPimages().get(0), iconImg, R.mipmap.icon_img_defeated);
        }
        toolbar.setTitle(productInfoBean.getPname());
        shopName.setText("积分：" + productInfoBean.getPprice());
        shopDesc.setText(productInfoBean.getPdesc());
    }

    @Override
    public int getTitleLeftName() {
        return R.mipmap.back_click;
    }

    @Override
    public void onClickTitleLeft() {
        ActivityManager.getInstance().finishActivity();
    }

    private void getproductinfobypid(String pid) {
        showDialog();
        UserProduct_RequestNet_Utils.getProductInfoByPid(ctx, pid, new CallBack<String>() {
            @Override
            public void onSuccess(String code, String msg, String s) {


            }

            @Override
            public void onFailure(String code, String msg, String body) {

            }

            @Override
            public void onError(String code, String msg) {

            }
        });
    }

}
